﻿@using System.Diagnostics;
@using System.Collections;
@using System.Reflection;
@using System.Runtime.Versioning;
@using Microsoft.AspNetCore.Http
@using NewLife.Common;
@using HttpContext = NewLife.Web.HttpContext
@inject IHttpContextAccessor HttpContextAccessor

@{
    //Layout = NewLife.Cube.Setting.Current.Layout;

    ViewBag.Title = "服务器变量列表";
    var httpContext = HttpContextAccessor.HttpContext;
    var req = httpContext.Request;
    // ASP.NET Core中没有ServerVariables的对应实现，需要换一种方式，可以在HttpContext.Request.Headers中获取
}
<table class="table table-bordered table-hover table-striped table-condensed">
    <tr>
        <th colspan="6">
            服务器变量列表
        </th>
    </tr>
    <tr>
        <th>名称</th>
        <th>数值</th>
    </tr>
    @foreach (var kv in req.Headers)
    {
        var v = kv.Value.ToString();
        v = v.Replace("\r\n", "</br>");
        var key = kv.Key;
        if (key.EqualIgnoreCase("HTTP_COOKIE")) { v = v.Replace(";", "</br>"); }
        <tr>
            <td>@key</td>
            <td>@Html.Raw(v)</td>
        </tr>
    }
</table>
<table class="table table-bordered table-hover table-striped table-condensed">
    <tr>
        <th colspan="6">
            Request变量列表&nbsp;&nbsp;&nbsp;&nbsp;@req.GetType().FullName
        </th>
    </tr>
    <tr>
        <th>名称</th>
        <th>数值</th>
    </tr>
    @foreach (var pi in req.GetType().GetProperties())
    {
        var type = pi.PropertyType;
        if (pi.GetIndexParameters().Length > 0 || (type != typeof(String)
                                                   && type != typeof(Uri)
                                                   && type != typeof(PathString)
                                                   && type != typeof(HostString)
                                                   && !typeof(Boolean).IsAssignableFrom(type)
                                                   && !typeof(String).IsAssignableFrom(type)))
        {
            continue;
        }
        var v = req.GetValue(pi) + "";
        v = v.Replace("\r\n", "</br>");
        <tr>
            <td>@pi.Name</td>
            <td>@Html.Raw(v)</td>
        </tr>
    }
</table>